package com.tyz.hellocst.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by ych on 2021/12/25.
 */


public class DBOpenHelper extends SQLiteOpenHelper{

    private static final String DB_NAME = "Sql.db";
    private static final String USERS_TABLE_NAME = "users";
    private static final String GOODS_TABLE_NAME = "goods";
    private static final int DB_VERSION = 1;

    public DBOpenHelper(Context context) {
        super(context,DB_NAME,null,DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        String users = "create table users(" +
                "userName varchar(20)," +
                "userMd5 varchar(32) primary key," +
                "userPwd varchar(20)," +
                "userNum varchar(20)," +
                "name varchar(20)," +
                "sex  varchar(5)" +
                ")";

        String goods = "create table goods(" +
                "goodsId varchar primary key," +
                "goodsName varchar(20)," +
                "goodsText text," +
                "goodsImage blob," +
                "goodsTime datetime," +
                "goodsPrice double," +
                "goodsOwner varchar(20)," +
                "goodsOwnerContact varchar(15)," +
                "goodsState integer not null default (0)," +
                "goodsBuyers varchar(20)" +
                ")";
        sqLiteDatabase.execSQL(users);
        sqLiteDatabase.execSQL(goods);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
